package com.cxhc.app.api;

import com.cxhc.app.api.mapper.CmAreaInfoMapStructMapper;
import com.cxhc.app.api.vo.CmAreaInfoVo;
import com.cxhc.common.annotation.Anonymous;
import com.cxhc.common.core.controller.BaseController;
import com.cxhc.common.core.domain.AjaxResult;
import com.cxhc.common.core.domain.R;
import com.cxhc.common.core.page.TableDataInfo;
import com.cxhc.system.domain.app.CmAreaInfo;
import com.cxhc.system.service.app.ICmAreaInfoService;
import com.cxhc.system.service.cockpit.IRpFeedbackService;
import com.cxhc.system.service.cockpit.ISysEntService;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 楼宇信息Controller
 * 
 * @author Dhq
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/api/statistics")
public class ApiStatistics extends BaseController
{
    @Autowired
    private ICmAreaInfoService cmAreaInfoService;

    @Resource
    private ISysEntService sysEntService;

    @Resource
    private IRpFeedbackService rpFeedbackService;

    /**
     * 查询楼宇信息列表
     */
    @PostMapping("/cmAreaInfo")
    @ResponseBody
    public TableDataInfo cmAreaInfoStatisticsList(@RequestBody CmAreaInfoVo cmAreaInfoVo)
    {
        PageHelper.startPage(cmAreaInfoVo.getPageNum(),cmAreaInfoVo.getPageSize());
        CmAreaInfo cmAreaInfo = CmAreaInfoMapStructMapper.INSTANCE.CmAreaInfoVoToCmAreaInfo(cmAreaInfoVo);
        List<CmAreaInfo> list = cmAreaInfoService.getCmAreaInfoStatisticsList(cmAreaInfo);
        return getDataTable(list);
    }

    /**
     * 查询楼宇,企业，员工，事件数量
     */
    @PostMapping("/count")
    @ResponseBody
    public Map<String,String> statistics()
    {
        return cmAreaInfoService.statisticsCount();
    }

    /**
     * 查询企业列表
     */
    @RequestMapping("/entList")
    @ResponseBody
    public TableDataInfo entListByAreaId(String areaId)

    {
        startPage();
        return getDataTable(cmAreaInfoService.entListByAreaId(areaId));
    }


    /**
     * 查询企业分类占比
     */
    @Anonymous
    @SneakyThrows
    @RequestMapping("/queryEntType")
    public R<Map<String,String>> queryEntByType(String date,String areaId) {
        return R.ok(sysEntService.selectEntByType(date,areaId));
    }

    /**
     * 查询企业分类占比
     */
    @Anonymous
    @SneakyThrows
    @RequestMapping("/queryEntEvent")
    public R<Map<String,String>> queryEntEvent(String date,String areaId) {
        return R.ok(sysEntService.queryEntEvent(date,areaId));
    }

    /**
     * 查询企业分类占比
     */
    @Anonymous
    @SneakyThrows
    @RequestMapping("/queryEntUser")
    public R<Map<String,String>> queryEntUser(String date,String areaId) {
        return R.ok(sysEntService.queryEntUser(date,areaId));
    }

    /**
     * 事件统计
     *
     * @return
     */
    @Anonymous
    @RequestMapping("/eventNum")
    private R<Map<String,String>> eventNum(String startTime,String endTime,String month) {
        return R.ok(rpFeedbackService.selectEventNum(startTime,endTime,month));
    }

    /**
     * 事件统计
     *
     * @return
     */
    @Anonymous
    @RequestMapping("/eventNumForWeek")
    private R<Map<String,Map<String,Object>>> eventNumForWeek(String isAlong) {
        return R.ok(rpFeedbackService.eventNumForWeek(isAlong));
    }

    /**
     * 事件统计
     *
     * @return
     */
    @Anonymous
    @RequestMapping("/eventNumForUser")
    private R<List<Map<String,Object>>> eventNumForUser(String isAlong,String status) {
        return R.ok(rpFeedbackService.eventNumForUser(isAlong,status));
    }


    /**
     * 事件统计
     *
     * @return
     */
    @Anonymous
    @RequestMapping("/eventNumByAcceptEntID")
    private R<Map<String,String>> eventNumByAcceptEntID(String startTime,String endTime,String isOver) {
        return R.ok(rpFeedbackService.eventNumByAcceptEntID(startTime,endTime,isOver));
    }

    /**
     * 事件统计
     *
     * @return
     */
    @Anonymous
    @RequestMapping("/eventNumByEntID")
    private R<Map<String,String>> eventNumByEntID(String startTime,String endTime) {
        return R.ok(rpFeedbackService.eventNumByEntID(startTime,endTime));
    }

    /**
     * 事件统计
     *
     * @return
     */
    @Anonymous
    @RequestMapping("/eventNumByRepairType")
    private R<Map<String,String>> eventNumByRepairType(String startTime,String endTime) {
        return R.ok(rpFeedbackService.eventNumByRepairType(startTime,endTime));
    }

    /**
     * 查询企业分类占比
     */
    @Anonymous
    @SneakyThrows
    @RequestMapping("/queryEntEventForArea")
    public R<Map<String,String>> queryEntEventForArea() {
        return R.ok(sysEntService.queryEntEventForArea());
    }

}
